#pragma once

#include"RB_Tree.h"

namespace bit
{
	template<class K, class T>
	class map
	{
	public:
		using V_type = pair<const K, T>;
		class MapKeyOfT
		{
		public:
			const K& operator()(const V_type& pair)
			{
				return pair.first;
			}
		};

	public:
		typedef typename RB_Tree<K, V_type, MapKeyOfT>::iterator iterator;
		typedef typename RB_Tree<K, V_type, MapKeyOfT>::const_iterator const_iterator;

		iterator begin()
		{
			return _RBT.begin();
		}

		iterator end()
		{
			return _RBT.end();
		}

		const_iterator begin() const
		{
			return _RBT.c_begin();
		}

		const_iterator end() const
		{
			return _RBT.c_end();
		}

		pair<iterator,bool> Insert(const V_type& pair)
		{
			return _RBT.Insert(pair);
		}

		iterator find(const K& key)
		{
			return _RBT.Find(key);
		}

		T& operator[](const K& key)
		{
			pair<iterator, bool>pai = _RBT.Insert({ key,T() });
		
			return pai.first->second;
		}
		
	private:

		RB_Tree<K, V_type, MapKeyOfT> _RBT;
	};
}